#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define DEBUG_STR(s) printf(#s":	%s\n",s);
#define DEBUG_INT(s) printf(#s":	%d\n",s);
#define DEBUG_CHAR(s) printf(#s:	%c\n",s);

enum TYPE{INT=0,FLOAT=1,DOUBLE=2,CHAR=3};	

struct __para_table__
{
	char *org_name;
	char *ptx_name;
	int isptr;
	enum TYPE type;
	struct __para_table__ * next;
};

typedef struct __para_table__ para_table;
char * modify_file(char *inputfilename,char *func_name)
{
	char *input_str,*input_str_cpy,*cur_token;
	input_str=(char *)malloc(sizeof(char)*255+1);
	FILE *fp=fopen(inputfilename,"r+");
//	fseek(fp,0,SEEK_SET);
	while (fgets(input_str,255,fp)!=NULL)
	{
		//DEBUG_STR(input_str);		
		input_str_cpy=(char *)malloc(sizeof(char)*strlen(input_str)+1);
		strcpy(input_str_cpy,input_str);
		cur_token=strtok(input_str_cpy," ");
		
		if (!strcmp(cur_token,"define"))
		{
			if (strstr(input_str,func_name)!=NULL)
			{
				int i;
				for (i=0;input_str[i]!='@';i++);
				input_str[i+1]+=1;
				fseek(fp,-strlen(input_str),SEEK_CUR);				
				fputs(input_str,fp);
				fseek(fp,strlen(input_str),SEEK_CUR);
				fclose(fp);
				fp=fopen(inputfilename,"a+");
				fputs("declare i32 @matrix_add(float* %A, float* %B, float* %C, i32 %W)"\
					,fp);
				fclose(fp);
							
			}
			
			return inputfilename;
		}
		else free(input_str);
		input_str=(char *)malloc(sizeof(char)*255+1);
	
	}				
}		
char * device_driver(char *filename)
{
	FILE *fp=fopen(filename,"r");
	char *cur_line;
	char *cur_token;
	char *input_str;
	cur_line=(char *)malloc(sizeof(char)*255);
	char *cur_line_cpy;
	while (fgets(cur_line,255,fp)!=NULL)
	{
	//	DEBUG_STR(cur_line);
		cur_line_cpy=(char *)malloc(strlen(cur_line)+1);
		strcpy(cur_line_cpy,cur_line);
		//DEBUG_STR(cur_line_cpy);		
		cur_token=strtok(cur_line_cpy," ");		
		if(!strcmp(cur_token,"define"))
		{
			FILE *fp_drv=fopen("fp_drv.c","w+");
		//	DEBUG_STR(cur_token);
			//initial the module C file
			input_str=(char *) malloc(sizeof(char)*strlen("#include <stdio.h>\n")+1);
			sprintf(input_str,"#include <stdio.h>\n");			
			fputs(input_str,fp_drv);
			free(input_str);

			input_str=(char *) malloc(sizeof(char)*strlen("#include <stdlib.h>\n")+1);
			sprintf(input_str,"#include <stdlib.h>\n");			
			fputs(input_str,fp_drv);
			free(input_str);

			input_str=(char *) malloc(sizeof(char)*(strlen("#include <cuda.h>\n")+2));
			sprintf(input_str,"#include <cuda.h>\n");
		//	DEBUG_STR(input_str);			
			fputs(input_str,fp_drv);
			free(input_str);

			input_str=(char *) malloc(sizeof(char)*strlen("#include <math.h>\n")+1);
			sprintf(input_str,"#include <math.h>\n");			
			fputs(input_str,fp_drv);
			free(input_str);
			
			//declare some little routines
			fputs("size_t LenofArray(float *p)\n{\n",fp_drv);
			fputs("size_t length=0;\nfor(;*p!=\'\\0\';p++)\nlength++;\nreturn length;\n}\n",fp_drv);
			
			//declare the function which intial the computing env as well as the device
			
			//function type
			char *func_type;
			cur_token=strtok(NULL," ");
	
			if (!strcmp(cur_token,"i32"))
			{
				func_type=(char *)malloc(sizeof(char)*strlen("int")+2);
				strcpy(func_type,"int ");
			}
			else return NULL;//here can extend the func type support
			cur_token=strtok(NULL,"(");
		
			input_str=(char *) malloc(sizeof(char)*(strlen(func_type)+strlen(cur_token)+1));
			char *func_name=(char *)malloc(sizeof(char)*strlen(cur_token)+1);
			int i;
			for (i=1;i<strlen(cur_token);i++) func_name[i-1]=cur_token[i];
			sprintf(input_str,"%s%s(",func_type,func_name);
		//	DEBUG_STR(cur_token);
			
			fputs(input_str,fp_drv);
			free(input_str);
			
			
			//build the parameter table when writing the prototype of function to the file
			int para_count=0;
			para_table *pt;
			para_table *cur_para,*rail;
			int k=0;
			char c;
			while ((cur_token=strtok(NULL,","))!=NULL)
			{
			/*	input_str=(char *) malloc(sizeof(char)*(strlen(cur_token)+2));
				sprintf(input_str,"%s%c",cur_token,c=(strchr(cur_token,')')==NULL)?',':')');*/
				//DEBUG_STR(cur_token);
				if (para_count==0)//the first count
				{
					//analysis the first parameter
					char *cur_token_cpy=(char *)malloc(sizeof(char)*strlen(cur_token));
					char *temp;
					strcpy(cur_token_cpy,cur_token);
					pt=(para_table *)malloc(sizeof(para_table));
					rail=pt;
					rail->next=NULL;
					para_count++;
					//above all are setting the table and the following is setting the cur_para
					pt->org_name=(char *)malloc(sizeof(char)*(strlen(cur_token)+1));
					pt->ptx_name=(char *)malloc(sizeof(char)*(strlen(cur_token)+1));
					//to get the para_type
					//we support float and integer only now
					for (i=0;cur_token_cpy[i]!=' ';i++);
				//	DEBUG_INT(i);
					temp=(char *)malloc(sizeof(char)*i+1);
					for (i=0;cur_token_cpy[i]!=' ';i++) temp[i]=cur_token_cpy[i];
					temp[i]='\0';
				//	DEBUG_STR(temp);
					int flag;
					if (temp[strlen(temp)-1]=='*') 
					{
						flag=1;
						pt->isptr=1;						
						switch(temp[strlen(temp)-2])
						{
							case 't': 
								pt->type=FLOAT;
								break;
							case '2':
								pt->type=INT;
								break;
						}
						
					}
					else 
					{
						flag=0;
						pt->isptr=0;						
						switch(temp[strlen(temp)-1])
						{
							case 't': 
								pt->type=FLOAT;
								break;
							case '2':
								pt->type=INT;
								break;
						}											
					}
					//to get the para_name
					for (i=0;cur_token[i]!='%';i++);
					i++;
					for (;i<strlen(cur_token)&&cur_token[i]!=')';i++) 
						pt->org_name[k++]=cur_token[i];
					pt->org_name[k++]='\0';
				//	DEBUG_STR(pt->org_name);
					if (cur_token[i]==')') c=')';
					else c=',';				
					k=0;//reset k
					//DEBUG(pt->org_name);
					pt->ptx_name=(char *)malloc(sizeof(char)*(strlen(pt->org_name)+4+1));
					sprintf(pt->ptx_name,"ptx_%s",pt->org_name);
					//DEBUG_STR(pt->org_name);
					
					if (pt->type==FLOAT)
					{
						input_str=(char *)malloc(sizeof(char)*(strlen(pt->org_name)\
							+strlen("float *%s%c")+7));						
						if (flag==1) sprintf(input_str,"float *%s%c",pt->org_name,c);
						else sprintf(input_str,"float %s%c",pt->org_name,c);
					}
					else 
					{
						input_str=(char *)malloc(sizeof(char)*(strlen(pt->org_name)\
							+strlen("int *%s%c")+7));
						if (flag==1) sprintf(input_str,"int *%s%c",pt->org_name,c);
						else sprintf(input_str,"int %s%c",pt->org_name,c);
					}
				//	DEBUG_STR(input_str);

					DEBUG_STR(pt->org_name);
					DEBUG_STR(pt->ptx_name);
					DEBUG_INT(pt->type);
					DEBUG_INT(pt->isptr);
					printf("\n");


					fputs(input_str,fp_drv);
					free(input_str);
					free(cur_token_cpy);
					free(temp);
									
				//	return 1;
				}//end if count_para=0
				else 
				{
					char *cur_token_cpy=(char *)malloc(sizeof(char)*strlen(cur_token));
					char *temp;
					int flag;
					strcpy(cur_token_cpy,cur_token);
					cur_para=(para_table *)malloc(sizeof(para_table));
					rail->next=cur_para;
					rail=cur_para;
					rail->next=NULL;
					para_count++;
					//above all are setting the table and the following is setting the cur_para
					cur_para->org_name=(char *)malloc(sizeof(char)*(strlen(cur_token)+1));
					cur_para->ptx_name=(char *)malloc(sizeof(char)*(strlen(cur_token)+1));
					//get para_type					
					//we support float and integer only now
					for (i=1;cur_token_cpy[i]!=' ';i++);
					temp=(char *)malloc(sizeof(char)*i+2);
				//	strcpy(temp,"    ");//it's strange here!!!
					for (i=1;cur_token_cpy[i]!=' ';i++) temp[i-1]=cur_token_cpy[i];
					temp[i-1]='\0';
					//DEBUG_STR(temp);
					//printf("%c\n",temp[1]);
					//return NULL;
					if (temp[strlen(temp)-1]=='*') 
					{
						flag=1;	
						cur_para->isptr=1;						
						switch(temp[strlen(temp)-2])
						{
													
							case 't': 
								cur_para->type=FLOAT;
								break;
							case '2':
								cur_para->type=INT;
								break;
						}
					}
					else 
					{
						flag=0;	
						cur_para->isptr=0;					
						switch(temp[strlen(temp)-1])
						{
													
							case 't': 
								cur_para->type=FLOAT;
								break;
							case '2':
								cur_para->type=INT;
								break;
						}											
					}
				//	DEBUG_INT(cur_para->type);
				//	DEBUG_INT(cur_para->isptr);
					//to get the para_name
					for (i=0;cur_token[i]!='%';i++);
					i++;
					//DEBUG_INT(k);
					for (;i<strlen(cur_token)&&cur_token[i]!=')';i++) cur_para->org_name[k++]=cur_token[i];
					cur_para->org_name[k++]='\0';
				//	DEBUG_STR(cur_para->org_name);
					if (cur_token[i]==')') c=')';
					else c=',';
					k=0;//reset k
					cur_para->ptx_name=(char *)malloc(sizeof(char)*(strlen(cur_para->org_name)+4+1));
					sprintf(cur_para->ptx_name,"ptx_%s",cur_para->org_name);

					if (cur_para->type==FLOAT)
					{
						input_str=(char *)malloc(sizeof(char)*(strlen(cur_para->org_name)\
								+strlen("float *%s%c")+7));						
						if (flag==1) sprintf(input_str,"float *%s%c",cur_para->org_name,c);
						else sprintf(input_str,"float %s%c",cur_para->org_name,c);
					}
					else 
					{
						input_str=(char *)malloc(sizeof(char)*(strlen(cur_para->org_name)\
								+strlen("int *%s%c")+7));						
						if (flag==1) sprintf(input_str,"int *%s%c",cur_para->org_name,c);
						else sprintf(input_str,"int %s%c",cur_para->org_name,c);
					}
					//DEBUG_STR(input_str);

					DEBUG_STR(cur_para->org_name);
					DEBUG_STR(cur_para->ptx_name);
					DEBUG_INT(cur_para->type);
					DEBUG_INT(cur_para->isptr);
					printf("\n");
				
					fputs(input_str,fp_drv);
					free(input_str);
				//	free(cur_token_cpy);
					free(temp);
				}//end else
					
			}//end while for building the para table

			//debug the para_table
			for (cur_para=pt;cur_para!=NULL;cur_para=cur_para->next)
			{
				DEBUG_STR(cur_para->org_name);
				DEBUG_STR(cur_para->ptx_name);
				DEBUG_INT(cur_para->type);
				DEBUG_INT(cur_para->isptr);
				printf("\n");
			}
			fputs("\n{\n",fp_drv);		


			//begin to write the statements
			
			//set the module file and the funcname	
			input_str=(char *)malloc(sizeof(char)*(strlen(func_name)*2+40+1));
			sprintf(input_str,"char * p=\"%s.ptx\";\nchar * p_ker=\"%s\";\n",func_name,func_name);
			fputs(input_str,fp_drv);
			free(input_str);

			// Get number of devices supporting CUDA
			input_str=(char *)malloc(sizeof(char)*(strlen("if (cuInit(0) != CUDA_SUCCESS) exit (0);")+5));
			sprintf(input_str,"if (cuInit(0) != CUDA_SUCCESS) exit (0);\n");
			fputs(input_str,fp_drv);
			free(input_str);
			
			//detect the device 
			input_str=(char *)malloc(sizeof(char)*(strlen("int deviceCount = 0;")\
				+strlen("cuDeviceGetCount(&deviceCount);")+5));
			sprintf(input_str,"int deviceCount = 0;\ncuDeviceGetCount(&deviceCount);\n");
			fputs(input_str,fp_drv);
			free(input_str);
			input_str=(char *)malloc(sizeof(char)*(strlen("if (deviceCount == 0) {")\
				+strlen("printf(\"There is no device supporting CUDA.\n\");")\
				+strlen("exit (0);\n")\
				+strlen("}\n")+2));
			sprintf(input_str,"if (deviceCount == 0)\n{\nprintf(\"There is no device supporting CUDA.\");\nexit (0);\n}\n");
			fputs(input_str,fp_drv);
			free(input_str);
			
			 // Get handle for device 0
			input_str=(char *)malloc(sizeof(char)*(strlen("CUdevice cuDevice_drv = 0;\n")\
					+strlen("cuDeviceGet(&cuDevice_drv, 0);\n")+2));
			sprintf(input_str,"CUdevice cuDevice_drv = 0;\ncuDeviceGet(&cuDevice_drv, 0);\n");
			fputs(input_str,fp_drv);
			free(input_str);
				
			  // Create context
			input_str=(char *)malloc(sizeof(char)*(strlen("CUcontext cuContext_drv;\n")\
					+strlen("cuCtxCreate(&cuContext_drv, 0, cuDevice_drv);\n")+2));
			sprintf(input_str,"CUcontext cuContext_drv;\ncuCtxCreate(&cuContext_drv, 0, cuDevice_drv);\n");
			fputs(input_str,fp_drv);
			free(input_str);
			
			// Create module from binary file
			input_str=(char *)malloc(sizeof(char)*(strlen("CUmodule cuModule_drv;\n")\
					+strlen("cuModuleLoad(&cuModule_drv, p);\n")+2));
			sprintf(input_str,"CUmodule cuModule_drv;\ncuModuleLoad(&cuModule_drv, p);\n");
			fputs(input_str,fp_drv);
			free(input_str);

			 // Get function handle from module
			input_str=(char *)malloc(sizeof(char)*(strlen("CUfunction  vecAdd;\n")\
					+strlen("cuModuleGetFunction(&vecAdd,cuModule_drv,p_ker);\n")+2));
			sprintf(input_str,"CUfunction  vecAdd;\ncuModuleGetFunction(&vecAdd,cuModule_drv,p_ker);\n");
			fputs(input_str,fp_drv);
			free(input_str);
						

			//define the marco
			input_str=(char *)malloc(sizeof(char)*(strlen("#define ALIGN_OFFSET(offset, alignment) \
(offset) = ((offset) + (alignment) - 1) & ~((alignment)-1)\n"))+2);
			sprintf(input_str,"#define ALIGN_OFFSET(offset, alignment) (offset) = ((offset) + (alignment) - 1) & ~((alignment)-1)\n");
			fputs(input_str,fp_drv);
			free(input_str);

			//define the offset
			input_str=(char *)malloc(sizeof(char)*(strlen("int offset = 0;\nint size;\n"))+2);
			sprintf(input_str,"int offset = 0;\nsize_t size;\n");
			fputs(input_str,fp_drv);
			free(input_str);

			//define the void pointer
			input_str=(char *)malloc(sizeof(char)*strlen("void *  ptr;\n")+2);
			sprintf(input_str,"void *  ptr;\n");
			fputs(input_str,fp_drv);
			free(input_str);

			//begin to declare parameters from para_table
		
			for (cur_para=pt;cur_para!=NULL;cur_para=cur_para->next)
			{
				//CUdeviceptr and malloc the size;
				if (cur_para->isptr==1)
				{
					input_str=(char *)malloc(sizeof(char)*(strlen("CUdeviceptr %s;\n")+strlen(cur_para->ptx_name))+2);
					sprintf(input_str,"CUdeviceptr %s;\n",cur_para->ptx_name);
					fputs(input_str,fp_drv);
					free(input_str);
				//compute the size
					if (cur_para->type==FLOAT)
					{
						input_str=(char *)malloc(sizeof(char)*(strlen("size=sizeof(float)*LenofArray(%s);\n")\
							+strlen(cur_para->org_name))+2);
						sprintf(input_str,"size=sizeof(float)*LenofArray(%s);\n",cur_para->org_name);
						fputs(input_str,fp_drv);
						free(input_str);
					}
					else
					{
						input_str=(char *)malloc(sizeof(char)*(strlen("size=sizeof(int)*LenofArray(%s);\n")\
							+strlen(cur_para->org_name))+2);
						sprintf(input_str,"size=sizeof(int)*LenofArray_int(%s);\n",cur_para->org_name);
						fputs(input_str,fp_drv);
						free(input_str);
					}
					//cuMemAlloc;
					input_str=(char *)malloc(sizeof(char)*(strlen("cuMemAlloc(&%s, size);\n")+strlen(cur_para->ptx_name))+2);
					sprintf(input_str,"cuMemAlloc(&%s, size);\n",cur_para->ptx_name);
					fputs(input_str,fp_drv);
					free(input_str);
									//copy data from host to device

					input_str=(char *)malloc(sizeof(char)*(strlen("cuMemcpyHtoD(%s,%s,size);\n")+strlen(cur_para->ptx_name)\
							+strlen(cur_para->org_name))+2);
					sprintf(input_str,"cuMemcpyHtoD(%s, %s, size);\n",cur_para->ptx_name,cur_para->org_name);
					fputs(input_str,fp_drv);
					free(input_str);
					//set  para
					input_str=(char *)malloc(sizeof(char)*(strlen("ptr = (void**)(size_t)%s;\n")\
							+strlen(cur_para->ptx_name)+strlen("ALIGN_OFFSET(offset, __alignof(ptr));\n"))+2);
					sprintf(input_str,"ptr = (void**)(size_t)%s;\nALIGN_OFFSET(offset, __alignof(ptr));\n",cur_para->ptx_name);
					fputs(input_str,fp_drv);
					free(input_str);
				
					input_str=(char *)malloc(sizeof(char)*(strlen("cuParamSetv(vecAdd, offset, &ptr, sizeof(ptr));\n")\
							+strlen("offset += sizeof(ptr);\n"))+2);
					sprintf(input_str,"cuParamSetv(vecAdd, offset, &ptr, sizeof(ptr));\noffset += sizeof(ptr);\n");
					fputs(input_str,fp_drv);
					free(input_str);
				
				}
				else 
				{
					if (cur_para->type==FLOAT)
					{
						input_str=(char *)malloc(sizeof(char)*(strlen("size=sizeof(float)"))+2);
						sprintf(input_str,"size=sizeof(float);\n");
						fputs(input_str,fp_drv);
						free(input_str);
						input_str=(char *)malloc(sizeof(char)*(strlen(cur_para->org_name)\
								+strlen("ALIGN_OFFSET(offset, __alignof(%s));\n"))+2);
						sprintf(input_str,"ALIGN_OFFSET(offset, __alignof(%s));\n",cur_para->org_name);
						fputs(input_str,fp_drv);
						free(input_str);
						input_str=(char *)malloc(sizeof(char)*(strlen("cuParamSetf(vecAdd, offset,%s));\n")\
							+strlen("offset += sizeof(%s);\n"))+2+strlen(cur_para->org_name)*2);
						sprintf(input_str,"cuParamSetf(vecAdd, offset, %s);\noffset += sizeof(%s);\n",cur_para->org_name,\
							cur_para->org_name);
						fputs(input_str,fp_drv);
						free(input_str);
				
					}
					else
					{
						input_str=(char *)malloc(sizeof(char)*(strlen("size=sizeof(int)"))+2);
						sprintf(input_str,"size=sizeof(int);\n");
						fputs(input_str,fp_drv);
						free(input_str);

						input_str=(char *)malloc(sizeof(char)*(strlen(cur_para->org_name)\
								+strlen("ALIGN_OFFSET(offset, __alignof(%s));\n"))+2);
						sprintf(input_str,"ALIGN_OFFSET(offset, __alignof(%s));\n",cur_para->org_name);
						fputs(input_str,fp_drv);
						free(input_str);

						input_str=(char *)malloc(sizeof(char)*(strlen("cuParamSeti(vecAdd, offset,%s));\n")\
							+strlen("offset += sizeof(%s);\n"))+2+strlen(cur_para->org_name)*2);
						sprintf(input_str,"cuParamSeti(vecAdd, offset, %s);\noffset += sizeof(%s);\n",\
							cur_para->org_name,cur_para->org_name);
						fputs(input_str,fp_drv);
						free(input_str);
					}
				}//end of not a pointer						
			        fputs("\n",fp_drv);
				
			}//end of set all parameters
			
			input_str=(char *)malloc(sizeof(char)*strlen("cuParamSetSize(vecAdd, offset);\n")+1);
			sprintf(input_str,"cuParamSetSize(vecAdd, offset);\n");
			fputs(input_str,fp_drv);
			free(input_str);	
			

			//set block and grid size
			fputs("int blocksize=16;\n",fp_drv);
			input_str=(char *)malloc(sizeof(char)*(strlen("int gridsize=(int)sqrt(LenofArray(%s)/blocksize);\n")+strlen(pt->org_name))+2);
			sprintf(input_str,"int gridsize=(int)sqrt(LenofArray(%s))/blocksize;\n",pt->org_name);
			fputs(input_str,fp_drv);
			free(input_str);
			
			input_str=(char *)malloc(sizeof(char)*(strlen("cuFuncSetBlockShape(vecAdd,blocksize,blocksize,1);\n")\
					+strlen("cuLaunchGrid(vecAdd,gridsize,gridsize);\n"))+2);
			sprintf(input_str,"cuFuncSetBlockShape(vecAdd,blocksize,blocksize,1);\ncuLaunchGrid(vecAdd,gridsize,gridsize);\n");
			fputs(input_str,fp_drv);
			free(input_str);

			//cuMemcpyDtoH
			for (cur_para=pt;cur_para!=NULL;cur_para=cur_para->next)
			{
				if (cur_para->isptr==1)
				{
					if (cur_para->type==FLOAT)
					{
						input_str=(char *)malloc(sizeof(char)*(strlen("size=sizeof(float)*LenofArray(%s);\n")\
							+strlen(cur_para->org_name))+2);
						sprintf(input_str,"size=sizeof(float)*LenofArray(%s);\n",cur_para->org_name);
						fputs(input_str,fp_drv);
						free(input_str);
					}
					else
					{
						input_str=(char *)malloc(sizeof(char)*(strlen("size=sizeof(int)*LenofArray(%s);\n")\
							+strlen(cur_para->org_name))+2);
						sprintf(input_str,"size=sizeof(int)*LenofArray_int(%s);\n",cur_para->org_name);
						fputs(input_str,fp_drv);
						free(input_str);
					}
				}
				else 
				{
					if (cur_para->type==FLOAT)
					{
						input_str=(char *)malloc(sizeof(char)*(strlen("size=sizeof(float)"))+2);
						sprintf(input_str,"size=sizeof(float);\n");
						fputs(input_str,fp_drv);
						free(input_str);
					}
					else
					{
						input_str=(char *)malloc(sizeof(char)*(strlen("size=sizeof(int)"))+2);
						sprintf(input_str,"size=sizeof(int);\n");
						fputs(input_str,fp_drv);
						free(input_str);
					}
				}//end of not a pointer	
				
				if(cur_para->isptr==1)
				{ 		
					input_str=(char *)malloc(sizeof(char)*(strlen("cuMemcpyDtoH(%s,%s,size);\n")+strlen(cur_para->ptx_name)\
							+strlen(cur_para->org_name))+2);
					sprintf(input_str,"cuMemcpyDtoH(%s,%s,size);\n",cur_para->org_name,cur_para->ptx_name);
					fputs(input_str,fp_drv);
					free(input_str);
				}
				
			}//end of set all parameters
			fputs("return 1;\n}\n",fp_drv);
			fclose(fp);
			fclose(fp_drv);
		//	getchar();
			modify_file(filename,func_name);
			DEBUG_STR(func_name);
			char *ret=(char *)malloc(strlen("fp_drv.c")+1);
			strcpy(ret,"fp_drv.c");
			return ret;
		}//end if (cur_token=define)		
							
			
	}
	
}



